package cc.comac.mom.bean.base;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;

import cc.comac.mom.entity.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper=false)
public class LimitPageBean<T extends BaseEntity> extends BaseBean<BaseEntity>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    
	private int totalQuantity;
    private int pageCount;
    private int pageSize;
    private int pageNum;
    private List<?> entityList = new ArrayList<>();

    public static <T, N> LimitPageBean<?> of(IPage<T> page) {
    	LimitPageBean<?> paged = new LimitPageBean<>();
        paged.totalQuantity = (int)page.getTotal();
        paged.pageCount = (int) Math.ceil(page.getTotal() * 1.0d / page.getSize());
        paged.pageSize = (int)page.getSize();
        paged.pageNum = (int)page.getCurrent();
        paged.entityList = page.getRecords();
        return paged;
    }
	

}
